/*****************************************************************************
*    Copyright (C)2003 Ali Corporation. All Rights Reserved.
*
*    File:     nim_m3327_autosearch.h
*
*    Description:    Header file for blind search.
*    History:
*           Date            Athor        Version          Reason
*	    ============	=============	=========	=================
*	1.	2005/06/10        Berg Xing       Ver 0.1       Create file.
*	2.  2005/06/16		  Berg Xing 	  Ver 0.2       Enlarge search bandwidth
*	3.  2005/06/27        Berg Xing       Ver 0.3       Code size optimize
*	4.  2005/06/28        Berg Xing       Ver 0.4       Remove warning information when compiling
*
*    Notes:
*****************************************************************************/
#ifndef __NIM_M3327_AUTOSEARCH_H__
#define __NIM_M3327_AUTOSEARCH_H__

#include <types.h>
#include <api/libc/printf.h>
#include <sys_config.h>

//#define NIM_AS_DEBUG		1

#define NOISE_LEVEL_TRH		500
#define SIGNAL_LEVEL_TRH	1000
#define SNR_TRH				2

#define		MAX_CH_NUMBER			32//maximum number of channels that can be stored


//#define		FREQ_SEARCH_START_INDEX		237
#define		FREQ_SEARCH_START_INDEX		170
//DC component corresponds to index 511
//frequency resolution is 90MHz/1024=0.08789MHz for asic version
//and 60MHz/1024=0.05859375MHz for FPGA version
//so FREQ_SEARCH_START_INDEX=max(round(511 - (analog filter bandwidth/0.08789)), 0)
//or FREQ_SEARCH_START_INDEX=max(round(511 - (analog filter bandwidth/0.05859375)), 0)
//analog filter bandwidth should be non negative and less than 45MHz

//#define		ANALOG_FILTER_BW			24
#define		ANALOG_FILTER_BW			30
//bandwidth of analog filter, at unit of MHz
//too small value will result in negative tuner shift frequency

#define		DELTA_FREQUENCY_SHIFT		7
//leave some interval from FFT window left side to possible channel rising edge 
//when tune tuner mixer frequency, at unit of MHz
//7MHz is maximum roll off bandwidth of DVB-S signal, ie., when symbol rate is 45Msps

#define		STATISTIC_LENGTH			2
//average length of data to determine threshold
//0:2;1:4;2:8

#define		MIN_NOISE_LENGTH			4
//0.05859375MHz*MIN_NOISE_LENGTH = minimum bandwidth of data to be taken as noise in FPGA version
//0.08789MHz*MIN_NOISE_LENGTH = minimum bandwidth of data to be taken as noise in asic version

#define		MIN_SIGNAL_LENGTH			13//18
//0.05859375MHz*MIN_SIGNAL_LENGTH = minimum bandwidth of data to be taken as signal in FPGA version
//0.08789MHz*MIN_SIGNAL_LENGTH = minimum bandwidth of data to be taken as signal in asic version





extern INT32 nim_m3327_autosearch(INT32* success, INT32* delta_fc_est, INT32* SymbolRate_est, INT32* m_IF_freq, INT32* m_ch_number, UINT32 ana_filter_BW);
extern void nim_m3327_smoothfilter(void);

#endif

